#include <iostream>
using namespace std;

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string>
#include <cstring>
#define BUFFER_SIZE 16

int main()
{   
    const char * filename = "test.txt";

    //打开文件
    int fd1 = open(filename,O_RDWR | O_CREAT,0644);
    if(fd1 == -1)
    {
        perror("open error:");
    }

    char buffer[16];
    //清除脏数据
    bzero(buffer,sizeof(buffer));

    size_t readBytes = read(fd1,buffer,sizeof(buffer)-1);
    printf("readBytes = %ld,\tbuffer = %s\n",readBytes,buffer);

    off_t offset = lseek(fd1,0,SEEK_CUR);
    cout<<"offset:"<<offset<<endl;

    offset = lseek(fd1,0,SEEK_SET);
    cout <<"offset:"<<offset<<endl;
    
    readBytes = read(fd1,buffer,sizeof(buffer)-1);
    printf("readBytes = %ld,\tbuffer = %s\n",readBytes,buffer);

    offset = lseek(fd1,0,SEEK_END);
    cout<<"offset:"<<offset<<endl;

    close(fd1);

}